package com.future.init;

import com.future.demo.domain.Person;
import com.future.demo.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 在spring boot启动完成之后会执行的方法
 *
 * 这里只是举例，比如初始化一些数据，当然初始化数据和脚本升级管理可以考虑集成flyway
 *
 * @author WUWY
 * @create 2018-05-12 上午10:55
 **/
@Component
public class InitData implements CommandLineRunner {

    @Autowired
    private PersonService personService;

    @Override
    public void run(String... args) throws Exception {

        Person person = new Person();
        person.setFirstname("wu");
        person.setLastname("wenyu");

        Person person1 = new Person();
        person1.setFirstname("zou");
        person1.setLastname("shuiyun");

        Person person2 = new Person();
        person2.setFirstname("wu");
        person2.setLastname("baiyun");

        personService.add(person);
        personService.add(person1);
        personService.add(person2);
    }
}
